package com.tripwego.client.ui.widget;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.tripwego.client.event.MajLblInfosEvent;
import com.tripwego.client.event.MajLblInfosEventHandler;
import com.tripwego.client.ui.pageVoyage.IVoyageView;

public class InfosWidget extends Composite implements IVoyageView, MajLblInfosEventHandler {

	private Presenter presenter;

	private EventBus eventBus;

	/*
	 * Elements graphiques
	 */
	private HorizontalPanel viewPanel = new HorizontalPanel();

	private HorizontalPanel panel_aCentrer = new HorizontalPanel();

	private Label lbl_message = new Label();

	/**
	 * 
	 */
	public InfosWidget(String message) {
		super();

		viewPanel.setStyleName("divCenter_InfosWidget");

		viewPanel.add(panel_aCentrer);
		viewPanel.setCellHorizontalAlignment(panel_aCentrer, HasHorizontalAlignment.ALIGN_CENTER);

		panel_aCentrer.setStyleName("InfosWidget");
		panel_aCentrer.add(lbl_message);

		initWidget(viewPanel);
		
		lbl_message.setText(message);
	}

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}

	@Override
	public void setEventBus(EventBus eventBus) {
		this.eventBus = eventBus;

		// ecouteurs d'evenements
		eventBus.addHandler(MajLblInfosEvent.TYPE, this);
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
	}

	@Override
	public void handleMajLblInfosEvent(MajLblInfosEvent event) {
		if (!event.getMessage().isEmpty()) {
			lbl_message.setText(event.getMessage());
			setVisible(true);
		} else {
			setVisible(false);
		}
	}
}
